package com.csw.android.dev_utils.ex

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

/**
 * 通过Tag查找Fragment，若不存在实例，则重新创建一个Fragment
 */
inline fun <reified F : Fragment> FragmentManager.findOrCreateFragmentByTag(
    fragmentTag: String
): F {
    val existInstance = findFragmentByTag(fragmentTag)
    return if (existInstance is F) {
        existInstance
    } else {
        F::class.java.newInstance()
    }
}